package org.jeecg.modules.api.red.mapper;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.api.red.entity.RedCreate;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Description: 红包配置
 * @Author: jeecg-boot
 * @Date:   2024-10-14
 * @Version: V1.0
 */
public interface RedCreateMapper extends BaseMapper<RedCreate> {

    @Update("update fx_red_create set remain=remain-1 where id=#{id} and remain>=1")
    int subRemain(@Param("id") String id);

    @Update("update fx_red_create set state=1 where id=#{id} and remain=0")
    int updateFinishState(@Param("id") String id);

    Page<RedCreate> selectByPage(@Param("page") Page<RedCreate> page, Map<String,String> entity);

    @Select("select r.* from fx_red_create r left join fx_red_record re on r.id=re.red_id where re.member_id=#{memberId} and r.remain>0 and expire_time>now() limit 1")
    RedCreate getJoinIng(@Param("memberId") String memberId);

}
